var BmiAssistant = Class.create(AbstractModule, {

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'Imp'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));

	this.controller.setupWidget("heightField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: height});
	this.controller.setupWidget("weightField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: weight});
	
},

unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("heightUnit").update("<span class=\"si\">(in)</span>");
$("weightUnit").update("<span class=\"si\">(lb)</span>");
}

if (unitchoice){
$("heightUnit").update("<span class=\"si\">(cm)</span>");
$("weightUnit").update("<span class=\"si\">(kg)</span>");
}
},

	calculate: function() {
	var result = bmicalc(this.togglemodel.togglestate, $("heightField").mojo.getValue(), $("weightField").mojo.getValue());
	height=result.height;
	weight=result.weight;
	var interp="normal";
	if (result.bmi>29.99) {
  interp="obese";
  }
	
	if (result.bmi<18.5) {
  interp="underweight";
  }
	
	if ((result.bmi>24.99) && (result.bmi<30)) {
  interp="overweight";
  }
	

	return "The BMI is " + result.bmi + "<br/>This is in the "+ interp + " range.";
	}
});




